package com.ym.controller.soso;

import com.github.pagehelper.PageInfo;
import com.ym.common.utils.page.PageDomain;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.soso.domain.param.ChinaMedicineQueryParam;
import com.ym.soso.domain.param.ChinaMedicineUpdateParam;
import com.ym.soso.domain.vo.ChinaMedicineListPcVO;
import com.ym.soso.domain.vo.ChinaMedicineVO;
import com.ym.soso.service.IChinaMedicineSV;
import com.ym.soso.domain.param.PublishParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

import static com.ym.common.constant.ValidRule.Add;
import static com.ym.common.constant.ValidRule.Update;

/**
 * 中医堂信息Controller
 * 
 * @author ym
 * @date 2020-09-01
 */
@Api(tags = "medical-中医堂信息")
@RestController("ChinaMedicinePcController")
@Validated
@RequestMapping("/medical/chinaMedicine")
public class ChinaMedicineController extends BaseController {

    @Autowired
    private IChinaMedicineSV chinaMedicineSV;

    @ApiOperation("查询中医堂信息列表")
    @Log(dataBase = false, printBody = false, printQuery = true)
    @GetMapping("/list")
    public APIResponse<PageInfo<ChinaMedicineListPcVO>> list(@Valid ChinaMedicineQueryParam queryParam) {
        PageDomain.startPage();
        List<ChinaMedicineListPcVO> list = chinaMedicineSV.selectListPC(queryParam);
        return successPage(list);
    }

    @ApiOperation("详情")
    @Log(dataBase = false, printBody = false, printQuery = true)
    @GetMapping(value = "/info")
    public APIResponse<ChinaMedicineVO> info(@RequestParam Long id) {
        return successData(chinaMedicineSV.infoPc(id));
    }

    @ApiOperation("新增中医堂信息")
    @Log(printQuery = false)
    @PostMapping("/insert")
    public APIResponse insert(@RequestBody @Validated(value = Add.class) ChinaMedicineUpdateParam updateParam) {
        Long id = chinaMedicineSV.insertPC(updateParam);
        return successData(id);
    }

    @ApiOperation("修改中医堂信息")
    @Log(printQuery = false)
    @PostMapping("/update")
    public APIResponse update(@RequestBody @Validated(value = Update.class) ChinaMedicineUpdateParam updateParam) {
        int result = chinaMedicineSV.updateByIdPC(updateParam);
        return successData(result);
    }

    @ApiOperation("删除中医堂信息")
    @Log(printQuery = false)
    @PostMapping("/delete")
    public APIResponse delete(@RequestBody @Valid @NotNull Long[] ids) {
        int result = chinaMedicineSV.delete(ids);
        return successData(result);
    }

    @Log(dataBase = true)
    @ApiOperation("发布")
    @PostMapping("/publish")
    @ResponseBody
    public APIResponse publish(
            @RequestBody @Valid PublishParam params
    ) {
        int result = chinaMedicineSV.publish(params);
        return success();
    }
}
